home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / BC_TI.ARJ / TI724.ASC < prev    next >
Text File  |  1992-02-25  |  5KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  724
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/4
  12.  
  13.     TITLE  :  Example Mouse Event Handler
  14.  
  15.  
  16.  
  17.  
  18.   /**************************************************************
  19.     An example of using a mouse event handler.
  20.   **************************************************************/
  21.   #include <stdio.h>
  22.   #include <conio.h>
  23.   #include <dos.h>
  24.  
  25.   #define  MOUSEINT  geninterrupt( 0x33 )
  26.  
  27.   /*-- mouse event masks (use with M_event) --*/
  28.   #define  MOUSEMOVE      0x01        /* Use, for example:     */
  29.   #define  L_PRESS        0x02       /* L_PRESS | MOUSEMOVE  */
  30.   #define  L_RELEASE      0x04
  31.   #define  R_PRESS        0x08
  32.   #define  R_RELEASE      0x10
  33.  
  34.   /*-- mouse button status macros --*/
  35.   #define  L_DOWN         ( M_buttonstatus & 0x01 )
  36.   #define  R_DOWN         ( M_buttonstatus & 0x02 )
  37.  
  38.   #define  HANDLER_EXIT_PROCESSING()  \
  39.    __emit__( (unsigned char) 0x5D,  \
  40.              (unsigned char) 0x5F,  \
  41.              (unsigned char) 0x5E,  \
  42.              (unsigned char) 0x1F,  \
  43.              (unsigned char) 0x07,  \
  44.              (unsigned char) 0x5A,  \
  45.              (unsigned char) 0x59,  \
  46.              (unsigned char) 0x5B,  \
  47.              (unsigned char) 0x58,  \
  48.              (unsigned char) 0xCB  ) ;
  49.   #if 0
  50.   -------------------------------------------
  51.   The above emitted code is equivalent to the
  52.   following assembler code (but does not
  53.   require the -B compiling option):
  54.          asm  pop   bp    ;
  55.          asm  pop   di    ;
  56.          asm  pop   si    ;
  57.          asm  pop   ds    ;
  58.          asm  pop   es    ;     /* interrupt exit processing */
  59.          asm  pop   dx    ;
  60.          asm  pop   cx    ;
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  724
  75.   VERSION  :  2.0
  76.        OS  :  DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/4
  78.  
  79.     TITLE  :  Example Mouse Event Handler
  80.  
  81.  
  82.  
  83.  
  84.          asm  pop   bx    ;
  85.          asm  pop   ax    ;
  86.          asm  retf        ;     /* far return */
  87.   --------------------------------------------
  88.   #endif
  89.  
  90.   /*--Global mouse status variables --*/
  91.   int  M_xpos, M_ypos,         /* cursor location */
  92.        M_buttonstatus,         /* bits 0-2 ON if button is down */
  93.        M_eventcount,           /* # of times event has occurred */
  94.        M_event ;               /* flags a mouse event */
  95.  
  96.   /*-- Reset mouse -- returns # of buttons or 0 if problems --*/
  97.   int Mreset( void )
  98.   {
  99.    _AX = 0 ;
  100.    MOUSEINT ;
  101.    return( _AX  ?  _BX  : _AX ) ;
  102.   }
  103.  
  104.   /*-- Show mouse cursor --*/
  105.   void Mshow( void )
  106.   {
  107.    _AX = 1 ;
  108.    MOUSEINT ;
  109.   }
  110.  
  111.   /*-- Hide mouse cursor --*/
  112.   void Mhide( void )
  113.   {
  114.    _AX = 2 ;
  115.    MOUSEINT ;
  116.   }
  117.  
  118.   /*-- Get mouse position and button status --*/
  119.   void Mpos( void )
  120.   {
  121.    _AX = 3 ;
  122.    MOUSEINT ;
  123.    M_xpos = _CX ;
  124.    M_ypos = _DX ;
  125.    M_buttonstatus = _BX ;
  126.   }
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                            NUMBER  :  724
  141.   VERSION  :  2.0
  142.        OS  :  DOS
  143.      DATE  :  February 25, 1992                        PAGE  :  3/4
  144.  
  145.     TITLE  :  Example Mouse Event Handler
  146.  
  147.  
  148.  
  149.  
  150.   /*-- Installs mouse handler --*/
  151.   void Minsthandler( unsigned mask, void interrupt (*fn)(void) )
  152.   {
  153.    union REGS   reg ;
  154.    struct SREGS seg ;
  155.    reg.x.ax = 20 ;      /* mouse fn. 20 -- replaces fn.12 */
  156.    reg.x.cx = mask ;
  157.    reg.x.dx = FP_OFF( fn ) ;
  158.    seg.es = FP_SEG( fn ) ;
  159.    int86x( 0x33, ®, ®, &seg ) ;
  160.   }
  161.  
  162.   /*---------------------------------------------------------
  163.    This mouse event handler simply updates mouse information.
  164.   ----------------------------------------------------------*/
  165.   void interrupt mousehandler( void )
  166.   {
  167.    M_event = _AX ;
  168.    M_buttonstatus = _BX ;
  169.    M_xpos = _CX ;
  170.    M_ypos = _DX ;
  171.    HANDLER_EXIT_PROCESSING() ;
  172.   }
  173.  
  174.   /*----------------------------------------------------
  175.    Demonstrate mouse tracking via mouse event handler.
  176.   ----------------------------------------------------*/
  177.   main()
  178.   {
  179.    clrscr() ;
  180.    if( !Mreset() ) {
  181.       fputs("Cannot initialize mouse.", stderr) ;
  182.       exit(1) ;
  183.    }
  184.  
  185.    Minsthandler( MOUSEMOVE, mousehandler ) ;
  186.    M_event = 0 ;
  187.    Mshow() ;
  188.  
  189.    gotoxy(20,24) ;
  190.    cprintf("Text mode mouse tracking with event handler") ;
  191.    gotoxy(20,25) ;
  192.    cprintf("        Press any KEY to quit.") ;
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                            NUMBER  :  724
  207.   VERSION  :  2.0
  208.        OS  :  DOS
  209.      DATE  :  February 25, 1992                        PAGE  :  4/4
  210.  
  211.     TITLE  :  Example Mouse Event Handler
  212.  
  213.  
  214.  
  215.  
  216.    gotoxy( 1, 1) ;
  217.    cprintf("Position and button status is updated only when the
  218.             mouse moves.") ;
  219.    gotoxy( 1, 4);
  220.    cprintf("Button Status at time of handler call:") ;
  221.  
  222.    while( !kbhit() ) {
  223.       if( M_event ) {
  224.          gotoxy(1,2) ;
  225.          cprintf("Cursor position: %3d, %3d", M_xpos/8+1,
  226.                   M_ypos/8+1 ) ;
  227.          gotoxy(1,5) ;
  228.          L_DOWN ? cprintf("Left  DOWN") : cprintf("Left  UP  ") ;
  229.          gotoxy(20,5) ;
  230.          R_DOWN ? cprintf("Right DOWN") : cprintf("Right UP  ") ;
  231.          M_event = 0 ;      /* reset the event */
  232.       }
  233.    }
  234.    Mhide() ;
  235.    Mreset() ;
  236.   }
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.